/*
 * @Author: weikang
 * @Description:
 * @Date: 2024-01-27 15:23:44
 * @LastEditTime: 2024-01-27 22:36:14
 * @FilePath: \env-manager-pc\src\utils\dataHook\devices.ts
 */

export enum DeviceType {
  Produce = 'produce',
  Reuse = 'reuse',
  Electric = 'electric',
  ReuseParts = 'reuseParts',
}

export class Electric {
  public type: DeviceType
  constructor(data: any) {
    Object.assign(this, data)
    this.type = DeviceType.Electric
  }
}

export class Produce {
  public ElectricDevices: any[] = []
  public ObjID: string
  public type: DeviceType
  constructor(data: any) {
    this.ObjID = data.ObjID
    Object.assign(this, data)
    this.type = DeviceType.Produce
  }

  get Children() {
    return this.ElectricDevices.map(item => new Electric({ ...item, ParentId: this.ObjID }))
  }
}

export class Reuse extends Produce {
  constructor(data: any) {
    super(data)
    this.type = DeviceType.Reuse
  }
}

export class ReusesData {
  public ReuseParts: Reuse[]
  public type: DeviceType
  constructor(data: any) {
    this.ReuseParts = data.ReuseParts
    Object.assign(this, data)
    this.type = DeviceType.ReuseParts
    this.initPartData()
  }

  initPartData() {
    if (Array.isArray(this.ReuseParts)) {
      this.ReuseParts = this.ReuseParts.map(item => new Reuse(item))
    }
  }

  get Children() {
    return this.ReuseParts
  }
}
